<?php

class DefaultController extends Controller
{
	public function actionIndex($id=0)
	{
		//create division list
		$query = "SELECT * FROM `spm_divisi`";
		$command = Yii::app()->db->createCommand($query);
		$results = $command->query();
		
		//read
		$division = array();
		$index = 0;
		foreach($results as $row) {
			$division[$index] = $row['nama'];
			$index++;
		}
		
		//create pos 53 model
		$model53 = new Pos53();
		
		//check uploaded file
		if (isset($_POST['Pos53'])) {
			if ($model53->validate()) {
				//save
				
			}
		}
		
		
		//create pos 54 model
		$model54 = new Pos54('search');
		$model54->unsetAttributes();
		if(isset($_GET['Pos54'])) $model54->attributes=$_GET['Pos54'];
		
		//render
		$this->render('index',array('id'=>$id, 'division'=>$division,  'model53'=>$model53, 'model54'=>$model54));
	}
	
	public function actionUpdate($id, $divisi, $nilai) 
	{
		$query = "UPDATE `spm_pagu` AS a, `spm_pos` AS b, `spm_pos_keterangan` AS c SET nilai_rupiah=".$nilai." WHERE a.id_divisi=".$divisi." AND a.id_pos=b.id AND b.id_ket=c.id AND c.id=".$id;		
		$command = Yii::app()->db->createCommand($query);
		$results = $command->execute();
		
		if ($results>=0) echo "Debugging Purpose : Data Saved.";
		else echo "Debugging Purpose : Failed";
	}
}